<?php
	$conn=mysql_connect("localhost","root","vertrigo") or die("Không thể kết nối!");
	mysql_select_db("webqtd")or die("không tồn tại CSDL\"webqtd\"!");
	mysql_query("SET NAMES 'utf8'"); //Để hiển thị unicode
	session_start();
	$SoKheUoc = $_POST["SoKheUoc"];
	$SoHDTC = $_POST["SoHDTC"];
	$QuanHeVoiKH = $_POST["QuanHe"];
	$SoThangVay = $_POST["SoThangVay"];
	$LaiSuatQuaHan = $_POST["LaiSuatQuaHan"];
	$SoTienVay = $_POST["SoTienChoVay"];
	$MucDichChoVay = $_POST["MucDichVay"];
	$NgayLapHopDong = $_POST["NgayMoSo"];
	$NgayDenHan = $_POST["NgayDenHan"];
	$HinhThucXuLy = $_POST["HinhThucXuLy"];
	$MaKyHanTra = $_POST["MaKyHanTra"];
	
	$SoButToan = $_POST["SoButToan"];
	$hopdongtindung = new hopdongtindungbs();
	$hopdongtindung->SoKheUoc = $SoKheUoc;
	$hopdongtindung->SoHDTC = $SoHDTC;
	$hopdongtindung->QuanHeVoiKH = $QuanHeVoiKH;
	$hopdongtindung->SoThangVay = $SoThangVay;
	$hopdongtindung->LaiSuatQuaHan = $LaiSuatQuaHan;
	$hopdongtindung->SoTienVay = $SoTienVay;
	$hopdongtindung->MucDichChoVay = $MucDichChoVay;
	$hopdongtindung->NgayLapHopDong = $NgayLapHopDong;
	$hopdongtindung->NgayDenHan = $NgayDenHan;
	$hopdongtindung->HinhThucXuLy = $HinhThucXuLy;
	$hopdongtindung->MaKyHanTra = $MaKyHanTra;
	$kqhopdongtindung = $hopdongtindung->ThemHopDongTinDung();
	$kekhaigiaodich = new kekhaigiaodichbs();
	$kekhaigiaodich->SoButToan = $SoButToan;
	$kekhaigiaodich->MaLoaiGiaoDich = $_POST["MaLoaiGiaoDich"];
	$kekhaigiaodich->MaNguoiDung = $_POST["MaNhanVien"];
	$kekhaigiaodich->NgayGiaoDich = $NgayLapHopDong;
	$kekhaigiaodich->SoTienTaiKhoanCo =$SoTienVay;
	$kekhaigiaodich->SoKheUoc = $SoKheUoc;
	$kqgiaodich = $kekhaigiaodich->Them();
	
	if($kqhopdongtindung && $kqgiaodich)
 	{
		$nhatky = new nhatkybs();
 		$nhatky->TenSuKien = "Lập hợp đồng tín dụng";
		$nhatky->MaNguoiDung = $_SESSION["MaND"];
 		date_default_timezone_set('Asia/Ho_Chi_Minh');
		$nhatky->ThoiGian = date("Y-m-d H:m:s", time());
		$nhatky->Them();
 		$hinhthucvay = new hinhthucvaybs();
 		$hinhthucvay->MaHinhThucVay = $MaHinhThucVay;
		$dshinhthucvay = $hinhthucvay->LayDanhSach();
		header("Location:index.php?do=inphieuchitien&id=$SoKheUoc");
	}
 	else 
 	{
 		header("Location:index.php?do=laphopdongtindung");	
		$_SESSION["LoiThemHopDongTinDung"] = "Lỗi: " . mysql_error();
 	}
?>